package dao.oc_station_ice;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;

public class DaoImpl_Oc_Station_Ice extends HibernateDaoSupport implements
		Dao_Oc_Station_Ice {
	public void Insert_Oc_Station_Ice(EntityBeanOc_Station_Ice e) {
		this.getHibernateTemplate().save(e);
	}

	public void Update_Oc_Station_Ice(EntityBeanOc_Station_Ice e) {
		this.getHibernateTemplate().update(e);
	}

	@SuppressWarnings("unchecked")
	public void Delete_Oc_Station_Ice(String id) {
		List<EntityBeanOc_Station_Ice> list = this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where del='OFF' and id in(" + id
						+ ")");
		for (int i = 0; i < list.size(); i++) {
			EntityBeanOc_Station_Ice e = list.get(i);
			e.setDel("ON");
			this.getHibernateTemplate().update(e);

		}

	}

	@SuppressWarnings("unchecked")
	public EntityBeanOc_Station_Ice Find_Oc_Station_Ice_by_oc_id(Integer id) {
		EntityBeanOc_Station_Ice e = new EntityBeanOc_Station_Ice();
		List<EntityBeanOc_Station_Ice> list = this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where id=" + id);
		if (list.size() > 0) {
			e = list.get(0);
		}
		return e;
	}

	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station_Ice> Find_EntityBeanOc_Station_Ice() {
		List<EntityBeanOc_Station_Ice> list = new ArrayList<EntityBeanOc_Station_Ice>();
		list = this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where del='OFF' ");
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station_Ice> Find_Oc_Station_Ice_is_active() {
		return this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where del='OFF'");
	}

	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station_Ice> Find_Oc_Station_Ice_by_oc_voyage_id(
			Integer id) {
		return this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where del='OFF' and oc_voyage_id="
						+ id);
	}

	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station_Ice> Find_Oc_Station_Ice_by_oc_voyage_id(
			Integer id, Integer j) {
		return this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where territorial_waters=" + j
						+ " and del='OFF' and oc_voyage_id=" + id);
	}

	@SuppressWarnings("unchecked")
	public EntityBeanOc_Station_Ice Find_Oc_Station_Ice_by_L_D(String L,
			String D, String voyage) {
		EntityBeanOc_Station_Ice e = new EntityBeanOc_Station_Ice();
		List<EntityBeanOc_Station_Ice> list = this.getHibernateTemplate().find(
				"from EntityBeanOc_Station_Ice where del='OFF' "
						+ "and oc_voyage_id=" + voyage + " and longitude='" + L
						+ "' AND dimensionality='" + D + "'");
		if (list.size() > 0) {
			e = list.get(0);
		}
		return e;

	}
}
